/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *
 * @author Edwin
 */
public class Map {

    private String city1, city2;
    private Route route;
    private String nameFile, textInput, textOutput;

    public Map() {
    }

    public Map(String nameFile) {
        this.nameFile = "/home/edwinelpaisa/Documents/" + nameFile;
    }

    public void select() {
    }

    public void change() {
    }

    public void view() {
    }

    public int generateXML() {
        try {
            FileWriter fw = new FileWriter(nameFile);
            BufferedWriter out = new BufferedWriter(fw);
            PrintWriter salida = new PrintWriter(out);

            salida.write(textInput);
            out.flush();
            out.close();
            return 0;
        } catch (Exception e) {
            return -3;
            //System.out.println("Error de escritura, archivo de errores");
        }
    }

    public int loadXML() {
        try {
            File open = new File(this.nameFile); //Devuelve el File que vamos a leer
            if (open != null) {
                XML_Xerces fileXml = new XML_Xerces(this.nameFile);
                textOutput = fileXml.parseDocument();
                if(!textOutput.equals(""))
                    return 0; // Todo Correctamente
                else
                    return -5; //Estructura de XML Incorrecta
            }else
                return -4; //El archivo no existe
        } catch (Exception ioe) {
            return -3; //Error al leer el archivo
        }
    }

    /**
     * @return the city1
     */
    public String getCity1() {
        return city1;
    }

    /**
     * @param city1 the city1 to set
     */
    public void setCity1(String city1) {
        this.city1 = city1;
    }

    /**
     * @return the city2
     */
    public String getCity2() {
        return city2;
    }

    /**
     * @param city2 the city2 to set
     */
    public void setCity2(String city2) {
        this.city2 = city2;
    }

    /**
     * @return the route
     */
    public Route getRoute() {
        return route;
    }

    /**
     * @param route the route to set
     */
    public void setRoute(Route route) {
        this.route = route;
    }

    public String getTextInput() {
        return textInput;
    }

    public void setTextInput(String textInput) {
        this.textInput = textInput;
    }

    public void setNameFile(String nameFile) {
        this.nameFile = nameFile;
    }

    public String getNameFile() {
        return nameFile;
    }

    public String getTextOutput() {
        return textOutput;
    }

    public void setTextOutput(String textOutput) {
        this.textOutput = textOutput;
    }
}
